package com.pg.laboratory.actor;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.pg.free.util.Logger;

public class Runner extends Actor {

	private final int FRAME_COLS = 6;
	private final int FRAME_ROWS = 5;

	private Texture walkSheet;
	private TextureRegion[] walkFrames;
	private TextureRegion currentFrame;
	private Animation walkAnimation;
	private float stateTime;

	public Runner() {
		this.walkSheet = new Texture(
				Gdx.files.internal("image/laboratory/animation_sheet.png"));
		TextureRegion[][] tmp = TextureRegion.split(walkSheet,
				walkSheet.getWidth() / FRAME_COLS, walkSheet.getHeight()
						/ FRAME_ROWS);
		walkFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS];
		int index = 0;
		for (int i = 0; i < FRAME_ROWS; i++) {
			for (int j = 0; j < FRAME_COLS; j++) {
				walkFrames[index++] = tmp[i][j];
			}
		}
		walkAnimation = new Animation(0.025f, walkFrames); // #11		
		stateTime = 0f;
	}

	
	
	@Override
	public void act(float delta) {
		stateTime += delta;
        currentFrame = walkAnimation.getKeyFrame(stateTime, true);
	}



	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		batch.draw(currentFrame, 50, 50);
	}
}
